package com.lzl.ams.service;

import org.python.core.Py;
import org.python.core.PyString;
import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;

import java.io.StringWriter;
import java.util.List;

public class CodeRunner {

    static public String run(String code, List<String>opts){
        //PyString pycode = Py.newUnicode(code);
        PySystemState state = new PySystemState();
        for (String opt : opts) {
            state.argv.append(new PyString(opt));
        }
        PythonInterpreter interpreter = new PythonInterpreter(null,state);
        StringWriter out = new StringWriter();
        interpreter.setOut(out);
        interpreter.exec(code);
        return out.toString();
    }
}
